package cn.com.generaldata.os.common;

import org.dom4j.Document;
import org.dom4j.DocumentException;
import org.dom4j.DocumentHelper;
import org.dom4j.Node;

import cn.com.generaldata.os.builder.PacketRsBuilder;
import cn.com.generaldata.os.util.TransitionTool;
import cn.com.generaldata.os.vo.IdentityVO;

public class CommonPartVidate {
	/**
	 * 校验公共部分
	 * 
	 * @param xml
	 * @return
	 */
	public IdentityVO commonVidate(String xml) {
		IdentityVO identity = new IdentityVO();
		String serviceId = null;
		String channelId = null;
		Document document = null;
		// String filePath = getpath()+ "/xsd/common.xsd";
		// boolean check = new XMLCheck().Xml2Xsd(xml, filePath);
		PacketRsBuilder builder = new PacketRsBuilder();
		try {
			document = DocumentHelper.parseText(xml);
		} catch (DocumentException e1) {
			e1.printStackTrace();
		}
		Node node = document.selectSingleNode("package/identity");
		String x = node.asXML();
		try {
			IdentityVO commonWs = TransitionTool.fromXML(x, IdentityVO.class);
			serviceId = commonWs.getServiceId();
			channelId = commonWs.getChannelId();
			identity.setServiceId(serviceId);
			identity.setChannelId(channelId);
			builder.buildSuccessResult();
		} catch (Exception e) {
			e.printStackTrace();
			builder.buildErrorResult(e);
		}
		// }
		return identity;

	}
}
